from playwright.sync_api import sync_playwright
goods_list=[]
with sync_playwright()  as p:
    brower=p.chromium.launch(headless=True)
    page=brower.new_page()


    page.goto("https://uland.taobao.com/sem/tbsearch?bc_fl_src=tbsite_T9W2LtnM&channelSrp=bingSomama&clk1=ebefecab8ad4752d22c2172fdcf869b4&commend=all&ie=utf8&initiative_id=tbindexz_20170306&keyword=%E5%B7%A5%E8%A3%85%E8%A3%A4&localImgKey=&msclkid=54c9891832501bcbd3d6e18830fc4d03&page=1&preLoadOrigin=https%3A%2F%2Fwww.taobao.com&q=%E5%B7%A5%E8%A3%85%E8%A3%A4&refpid=mm_2898300158_3078300397_115665800437&search_type=item&sourceId=tb.index&spm=tbpc.pc_sem_alimama%2Fa.search_manual.0&ssid=s5-e&tab=all")
    pass#淘宝升级了反爬机制爬不了一点##
    goods_infos=page.locator(".CardV2--doubleCard--_OJ1T8j").all()
    for goods in goods_infos:
        goods_title=goods.locator(".Title--title--wJY8TeA ").text_content()
        goods_img=goods.locator(". MainPic--mainPicWrapper--varchHg").get_attribute("src")
        money1=goods.locator(".Price--priceInt--BXYeCOI").text_content()
        money2 = goods.locator(".Price--priceFloat--rI_BYho").text_content()
        price=money1+money2
        citys=goods.locator(".Price--procity--Na1DQVe")
        city1=citys[0].text_content()
        try:
            city2=citys[1].text_content
        except IndexError:
            city2=''
        city=city1+city2
        goods_store=goods.locator(".ShopInfo--shopNameText--kxQC2cC")
        goods_dict={
            "商品标题":goods_title,
            "商品图片地址":goods_img,
            "商品价格":price,
            "发货地":city,
            "店铺名":goods_store
        }
        goods_list.append(goods_dict)


print(len(goods_list))






